package com.masterclient.app.businessmodule.vipmodule.financial_management.api;


import com.eoner.baselib.container.CommonBaseResponse;
import com.eoner.managerlibrary.netsign.core.FCRetrofitManager;
import com.masterclient.app.businessmodule.vipmodule.financial_management.bean.BankCardBean;
import com.masterclient.app.businessmodule.vipmodule.financial_management.bean.CashBaseInfoData;
import com.masterclient.app.businessmodule.vipmodule.financial_management.bean.RechargeRecordData;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.RequestBody;


public class FinancialService {

    private static FinancialApi api;
    private static FinancialService instance;

    public static FinancialService getInstance() {
        synchronized (FinancialService.class) {
            if (instance == null) {
                instance = new FinancialService();
            }
        }
        return instance;
    }

    private FinancialService() {
        api = FCRetrofitManager.getInstance().getRetrofit().create(FinancialApi.class);
    }

    /**
     * 银行卡列表
     */
    public Observable<CommonBaseResponse<List<BankCardBean>>> bankCardList(){
        return api.bankCardList();
    }

    /**
     * 提现基本信息
     */
    public Observable<CommonBaseResponse<CashBaseInfoData>> cashBaseInfo(String withdraw_sourch){
        return api.cashBaseInfo(withdraw_sourch);
    }

    /**
     * 提现申请
     */
    public Observable<CommonBaseResponse> cashApply(String amount,String bankcard_cert_id
            ,String mobile,String captcha,String withdraw_source){
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("amount",amount);
            jsonObject.put("bankcard_cert_id",bankcard_cert_id);
            jsonObject.put("mobile",mobile);
            jsonObject.put("captcha",captcha);
            jsonObject.put("withdraw_source",withdraw_source);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),
                jsonObject.toString());
        return api.cashApply(body);
    }

    /**
     * 充值记录
     */
    public Observable<CommonBaseResponse<RechargeRecordData>> rechargeRecord(int page){
        return api.rechargeRecord(String.valueOf(page),"20");
    }

    /**
     * 提现记录
     */
    public Observable<CommonBaseResponse<RechargeRecordData>> cashRecord(int page,String withdraw_sourch){
        return api.cashRecord(String.valueOf(page),"20",withdraw_sourch);
    }

}
